package com.yklx.util;

import com.yklx.youke.YoukeApplication;
import com.yklx.youke.service.UserService;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.password.PasswordEncoder;

@Configuration
public class PasswordHashGenerator {

    public static void main(String[] args) {
        SpringApplication.run(YoukeApplication.class, args);
    }

    @Bean
    ApplicationRunner runner(PasswordEncoder passwordEncoder) {
        return args -> {
            String password = "admin123";
            String encodedPassword = passwordEncoder.encode(password);
            System.out.println("Original password: " + password);
            System.out.println("Encoded password: " + encodedPassword);
            System.out.println("Length: " + encodedPassword.length());
            
            // Verify the password
            boolean matches = passwordEncoder.matches(password, encodedPassword);
            System.out.println("Verification (should be true): " + matches);
            
            // Also check if the known hash works
            String knownHash = "$2a$10$e4hKoG9qvb62mgY9p6YtVOh.vVsP0X0Yh50r9bQzV3L6pUZq4L63a";
            boolean knownMatches = passwordEncoder.matches(password, knownHash);
            System.out.println("Known hash verification (should be true): " + knownMatches);
            
            System.exit(0);
        };
    }
}